﻿''' <summary>
''' プリンターリスト画面のフォームです。
''' </summary>
''' <remarks></remarks>
Public Class PrinterList
  Inherits Page

#Region " イベントハンドラ "
  Private Sub PrinterDataSource_Selected(
    sender As Object, e As ObjectDataSourceStatusEventArgs) Handles PrinterDataSource.Selected

    Me.CountLabel.Text = String.Format("{0} 個のオブジェクト", DirectCast(e.ReturnValue, ICollection).Count)
  End Sub

  Private Sub DetailDataSource_Selecting(
    sender As Object, e As ObjectDataSourceSelectingEventArgs) Handles DetailDataSource.Selecting

    If Me.PrinterListBox.SelectedIndex = -1 Then
      e.Cancel = True
    End If
  End Sub

  Private Sub DetailDataSource_Selected(
    sender As Object, e As ObjectDataSourceStatusEventArgs) Handles DetailDataSource.Selected

    Dim printer = DirectCast(e.ReturnValue, PrintQueue)
    ViewState("Speed") = printer.Speed
    ViewState("MaxResolution") = printer.MaxResolution
  End Sub

  '印刷速度、最高解像度の値変更
  Protected Sub TextBox_TextChanged(sender As Object, e As EventArgs)
    Dim txt = DirectCast(sender, TextBox)
    Dim stateKey = txt.ID.Replace("TextBox", String.Empty)
    Dim value As Integer

    If Int32.TryParse(txt.Text, value) = False Then   '整数に変換できない時
      Dim d As Decimal
      If Decimal.TryParse(txt.Text, d) Then   '実数には変換できる時
        txt.Text = Decimal.ToInt32(Decimal.Truncate(d)).ToString()  '小数部を切捨て
      Else  '実数にも変換できない時
        txt.Text = Convert.ToString(ViewState(stateKey))  '変更前の値に戻す
        txt.Focus()
      End If
    End If
    ViewState(stateKey) = txt.Text
  End Sub

  Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Response.Redirect("Main.aspx?idx=4")
  End Sub
#End Region
End Class